//
// Created by 董一龙 on 2022/10/13.
//

#ifndef FQUEUE_MMAP_QUEUE_H
#define FQUEUE_MMAP_QUEUE_H

#include <string>
#include "buffer/memory_map_buffer.h"
#include "operator/queue_operator_interface.h"
#include "operator/ring_buffer_operator.h"

namespace fqueue {
    class mmap_queue {
    private:
        using queue_operator_t = queue_operator_interface<ring_buffer_operator>;
        std::unique_ptr<memory_map_buffer> m_pBuffer;

    public:
        static size_t const DEFAULT_PART_QUEUE_FILE_SIZE = 1024 * 1024 * 16;

        mmap_queue() = delete;

        explicit mmap_queue(std::string const& filename, size_t mmap_size = DEFAULT_PART_QUEUE_FILE_SIZE);

        ~mmap_queue() = default;

        [[nodiscard]] size_t capacity() const;

        [[nodiscard]] size_t size() const;

        int enqueue(void const*input, size_t input_length);

        int dequeue(void *output, size_t output_length);
    };

} // fqueue

#endif //FQUEUE_MMAP_QUEUE_H
